package com.kcyu.sfherp.controller;


import com.kcyu.sfherp.entity.Chzd;
import com.kcyu.sfherp.entity.CkSale;
import com.kcyu.sfherp.entity.CkSaleLine;
import com.kcyu.sfherp.entity.CkStock;
import com.kcyu.sfherp.mapper.ck.CkSaleLineMapper;
import com.kcyu.sfherp.mapper.ck.CkSaleMapper;
import com.kcyu.sfherp.mapper.ck.CkStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ck")
public class CkController {

    @Autowired
    private CkStockMapper ckStockMapper;

    @Autowired
    private CkSaleMapper ckSaleMapper;

    @Autowired
    private CkSaleLineMapper ckSaleLineMapper;

    @RequestMapping(value = "/query",method = {RequestMethod.POST})
    public Map<Object,Object> query(@RequestBody Map info){
        String spname = (String) info.get("spname");

        List<CkStock> check = ckStockMapper.query(spname);
        Map<Object, Object> map = new HashMap<>();

        map.put("code",200);
        map.put("data",check);
        return map;
    }

    @RequestMapping(value = "/sale",method = {RequestMethod.POST})
    public Map<Object,Object> sale(@RequestBody Map info){
        String startTime = (String) info.get("startTime");
        String endTime = (String) info.get("endTime");

        List<CkSale> ckSales = ckSaleMapper.queryByTime(startTime, endTime);

        Map<Object, Object> map = new HashMap<>();

        map.put("code",200);
        map.put("data",ckSales);
        return map;
    }

    @RequestMapping(value = "/saleDetail/{BillID}",method = {RequestMethod.GET})
    public Map<Object,Object> saleDetail(@PathVariable String BillID){

        List<CkSaleLine> ckSales = ckSaleLineMapper.queryByBillID(BillID);

        Map<Object, Object> map = new HashMap<>();

        map.put("code",200);
        map.put("data",ckSales);
        return map;
    }

    @RequestMapping(value = "/pur",method = {RequestMethod.POST})
    public Map<Object,Object> pur(@RequestBody Map info){
        String startTime = (String) info.get("startTime");
        String endTime = (String) info.get("endTime");

        List<CkSale> ckSales = ckSaleMapper.queryPurByTime(startTime, endTime);

        Map<Object, Object> map = new HashMap<>();

        map.put("code",200);
        map.put("data",ckSales);
        return map;
    }

    @RequestMapping(value = "/purDetail/{BillID}",method = {RequestMethod.GET})
    public Map<Object,Object> purDetail(@PathVariable String BillID){

        List<CkSaleLine> ckSales = ckSaleLineMapper.queryPurByBillID(BillID);

        Map<Object, Object> map = new HashMap<>();

        map.put("code",200);
        map.put("data",ckSales);
        return map;
    }
}
